import { createElement } from '../../../utils/dom-helper';
import { IToolBase } from '../tools-base';
export function Select(opt: {icon: string, index?: number, title?: string, selsecClass: {new(): any}}) {
    return function(target: any, propertyKey: string) {
        // if(target.constructor.hasOwnProperty('__operate_select__') == false) {
        //     Object.defineProperty(target.constructor, '__operate_select__', {
        //         enumerable: false,
        //         value: []
        //     });
        // }
        // target.constructor['__icon_init__'].push(Object.assign(opt, {name: propertyKey}));
        if(target.constructor.hasOwnProperty('__icon_init__') == false) {
            Object.defineProperty(target.constructor, '__icon_init__', {
                enumerable: false,
                value: []
            });
        }
        (<any>target).constructor['__icon_init__'].push(function (toolInstance: IToolBase) {
                let ele = createElement('span', {'class': `icon iconfont icon-${opt.icon}`, title: opt.title});
                let instance = new opt.selsecClass();
                instance.init((<any>toolInstance)[propertyKey],ele, toolInstance);
                ele.addEventListener('click', () => {
                    instance.show();
                });
                toolInstance.container.appendChild(ele);
        });
    }
}